#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include "sqlite3.h"
using namespace std;

class Sqlite3Manager
{
private:
	sqlite3* _pdb;
public:
	Sqlite3Manager():_pdb(nullptr)
	{}

	void Open(const string& dbName)
	{
		if (sqlite3_open(dbName.c_str(), &_pdb) == SQLITE_OK)
			cout << "open database success" << endl;
		else
			cout << "open database false" << endl;
	}

	void Exec(const string& sql)
	{
		char* errmsg;
		if (sqlite3_exec(_pdb, sql.c_str(), nullptr, nullptr, &errmsg) == SQLITE_OK)
		{
			cout << "option success" << endl;
		}
		else
		{
			cout << "option false" << endl;
			cout << errmsg << endl;
			sqlite3_free(errmsg);
		}
	}

	void GetResultTable(const string& sql,char**& pRst,int& row,int& col)
	{
		char* zerrmsg;
		if (sqlite3_get_table(_pdb, sql.c_str(), &pRst, &row, &col, &zerrmsg) != SQLITE_OK)
		{
			cout << zerrmsg << endl;
			sqlite3_free(zerrmsg);
		}
	}

	void Close()
	{
		if (_pdb)
		{
			sqlite3_close(_pdb);
			_pdb = nullptr;
		}
	}

	~Sqlite3Manager(){}

};